/**
 * 项目中多个地方用到的接口方法，可在此处做处理，如此整个项目中都可以使用
 * obj 都为当前上下文  val是接口所需参数
 * @param getMenu 菜单列表
 ------------------------------------------------------------*/
import fetchService from "../fmlService/fetchService";
/**
 * isModule 1为菜单管理isModule:false  2为业务模块isModule:true  ''为所有不传isModule  isIndex是为首页的菜单树
 --------------------------*/
class PublicRe{
  async getMenu(obj, val, isModule, isIndex) {
    let select = [];
    let param = {};
    //菜单查询
    if (isModule == 1) {
      param = {
        isModule: false,
        parentId: val,
        isPagination: false
      };
    } else if (isModule == 2) {
      //业务模块
      param = {
        isModule: true,
        parentId: val,
        isPagination: false
      };
    } else if (isModule == 3) {
      //新增菜单
      param = {
        isModule: false,
        parentId: val,
        status: 1,
        isPagination: false,
        isSystem: 0
      };
    } else if (isModule == 4) {
      //首页设置
      param = {
        parentId: val
      };
    } else if (isModule == 5) {
      //无需懒加载
      param = {
        status: 1,
        isPagination: false,
        isLazy: 0,
        parentId: val
      }
    }
    else {
      param = {
        parentId: val,
        status: 1,
        isPagination: false
      };
    }
    let [err, result] = [{ message: '' }, { data: [] }];
    if (isIndex) {
      [err, result] = await fetchService.fetchGet(param, 'indexTree', false);
    } else {
      [err, result] = await fetchService.fetchGet(param, 'menuList', false);
    }

    if (err) {
      obj.$message({
        message: err.message || "获取数据失败",
        showClose: true,
        type: "error"
      });
      return [];
    }
    if (result.data && result.data.length > 0) {
      select = result.data;
      return select;
    } else {
      return [];
    }
  }
  async getOrganizate(obj,val,state) {
    let select = [];
    let param={}
    //state 1加载所有数据 0懒加载
    if(state==1){
      param={
        isPagination: false,
        isLazy:0,
        parentId:val
      }
    }else{
      param={
        parentId: val,
        isPagination: false
      }
    }
    let [err, result] = await fetchService.fetchGet(param,'organizationList',false);
    if (err) {
      obj.$message({
        message: err.message || "获取数据失败",
        showClose: true,
        type: "error"
      });
      return [];
    }
    if (result.data && result.data.length > 0) {
      select = result.data;
      return select;
    } else {
      return [];
    }
  };
}
const fmlRequest=new PublicRe()
export default fmlRequest
